/* The code examples copyrighted by Nokia Corporation that are included to
 * this material are licensed to you under following MIT-style License:
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import Qt 4.7
import Qt.labs.components 1.0
import com.meego 1.0


Window {
    Rectangle {
        id: page
        color: "white"
        anchors.fill: parent
	Column {
            id: column; spacing: 10
            anchors { fill: parent; topMargin: 10; bottomMargin: 10; leftMargin: 10; rightMargin: 10 }

            property real w: ((page.width - (spacing * 4)) / 3)

            Row {
                spacing:  10
                Button {
                    text: "Add"
                    width: column.w; height: 50
                    onClicked: { AccountsExample.addAccount();
                                 accountsView.currentIndex = 0;
                                 enableButton.text = AccountsExample.accountStatus(accountsView.currentIndex) ? "Disable": "Enable"
                    }
                }
                Button {
                    text: "Remove"
                    width: column.w; height: 50
                    onClicked: { AccountsExample.removeAccount(accountsView.currentIndex);
                                 enableButton.text = AccountsExample.accountStatus(accountsView.currentIndex) ? "Disable": "Enable"
                    }
                }
                Button {
                    id: enableButton
                    width: column.w; height: 50
                    text: AccountsExample.accountStatus(accountsView.currentIndex) ? "Disable": "Enable"
                    onClicked: { AccountsExample.toggleEnabled(accountsView.currentIndex);
                                 text = AccountsExample.accountStatus(accountsView.currentIndex) ? "Disable": "Enable"
                    }
                }
            }

            Row {
                Text { width: 0.2*page.width;  text: "<b>AccountId</b>" }
                Text { width: 0.3*page.width;  text: "<b>Display name</b>" }
                Text { width: 0.3*page.width;  text: "<b>Provider name</b>" }
                Text { width: 0.2*page.width;  text: "<b>Enabled</b>" }
            }

            ListView {
                id: accountsView
                width: page.width
                height: (page.height - 200)
                model: AccountsModel
                clip: true

                delegate: Item {
                    width: parent.width
                    height: 30
                    Row {
                        anchors.verticalCenter: parent.verticalCenter

                        Text { width: 0.2*page.width;  text: accountid }
                        Text { width: 0.3*page.width;  text: displayname }
                        Text { width: 0.3*page.width;  text: providername }
                        Text { width: 0.2*page.width;  text: accountenabled }
                    }
                    MouseArea { anchors.fill: parent;
                        onClicked: { accountsView.currentIndex = index; enableButton.text = AccountsExample.accountStatus(accountsView.currentIndex) ? "Disable": "Enable" }
                    }
                }
                highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
                highlightFollowsCurrentItem: true
            }
        }
        }
}
